<?php
/*  trophies 0.9.1
 
    Copyright (C) 2011  Vespo Marco | http://thelairofthemad.altervista.org/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

-----------------------------------------------------------------------------------------------*/
class trophies{

	private $br,$si,$go,$pl,$level;
	
	function __construct($level,$br,$si,$go,$pl){
		$this->br=$br;
		$this->si=$si;
		$this->go=$go;
		$this->pl=$pl;
		$this->level=(float)$this->loadLevel();
	}
	
	public function getBr(){return $this->br;}
	public function getSi(){return $this->si;}
	public function getGo(){return $this->go;}
	public function getPl(){return $this->pl;}
	public function getLevel(){return $this->level;}
	
	public function loadLevel() {
	    $points = $this->pl*180+$this->go*90+$this->si*30+$this->br*15; $p=0;
	    for ($x=1;$points>=$p;$x++) {
		$l=$p;
		switch ($x) {
		    case 1:$y=1;break; case 2:$p=200;break; case 3:$p*=3;break;
		    case 4:$p*=2;break; case 5:$p*=2;break; case 6:$p+=$p*2/3;break;
		    default:$n=$x-$y*6+1; $p+=$p*1/$n; if ($n==7) { $y++; }
		}
		if ($points <= $p) {
			if(($p-$l)>0)
		 		return $x+substr(($points-$l)/($p-$l),0,4)-1; 
		 	else return 0;		
		 }
	    }
	    return 0;
	}
	
	public function __toString() {return "level:".$this->level."&nbsp;bronze:".$this->br."&nbsp;silver:".$this->si."&nbsp;gold:".$this->go."&nbsp;platinum:".$this->pl."\n";}
}
?>
